package cn.com.elite;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient; 
import org.apache.http.message.BasicNameValuePair; 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.cntaiping.intserv.client.ISHttpClient;


public class ISPayThread implements Runnable{
	private static final Log log=LogFactory.getLog(ISPayThread.class);
	private boolean flag=true; //停止线程标记 
	public static String dotime;
	public static com.elitecrm.service.coresync.CoreSyncService coreSyncService;
	private String judge_daytime="";
	
	public String getDotime() {
		return dotime;
	}

	public void setDotime(String dotime) {
		this.dotime = dotime;
	}

	public static String getTxXml(String realtionID,DataSource dataSource1,String type){
		String TxXml="";
		String APPL_NO_QA="";
		try{
			String DIST="";
			String BUSI_pre="";
			String MAIN="";
			String TBR="";
			String BBR_pre="";
			String SYR="";
			String PT="";  
			String sql1="select W.CUSTLISTNAME,t1.ps_trans_way,to_char(t1.trans_date,'yyyymmdd') as TRANSFER_DATE123,t1.trans_comment,t1.ps_issue_mode,t1.trans_address," +
					"t1.bank_owner,case when s.ifpeixun='1' then s.tl_dept_code else r.dept_code end as dept_code,s.loginname as loginname1,to_char(t1.createddate,'yyyymmdd') as TRSDATE,CNTR_PRESS_NO,APPL_NO_QA," +
					"to_char(t1.toubao_date,'yyyymmdd') as APPDATE,t1.third_company_organ,p1.pol_code,t1.simple_id,t1.ERNST_MONEYIN_TYPE,t1.BANK_CODE," +
					"t1.BANKACC_NO,t1.BANKACC_TYPE,t1.MONEYIN_TYPE,t1.trans_way,to_char(t1.trans_date,'yyyymmdd') as DELIVER_DATE,t1.trans_address,s1.loginname," +
					"to_char(t1.qa_date,'yyyymmdd') as INSPECT_TIME,t1.premium*t1.mon_num_period*100 as INITIAL_PREMIUM,t1.mon_num_period,t1.trans_address,t1.account_owner," +
					"t1.ivr_paid_status,to_char(t1.ivr_paid_date,'yyyymmdd') as ivr_paid_date,t1.IVR_REAL_ORDER_NO as ivr_order_no,t1.ivr_bank_code,t1.ivr_paid_amt," +
					"i1.name as name1,i1.gender as gender1," +
					"to_char(i1.birthday,'yyyymmdd') as BIRTH1,i1.idtype as idtype1,i1.id as id1,i1.address as address1,i1.zipcode as zipcode1,i1.tel as tel1," +
					"i1.mobile as mobile1,i1.email as email1,i1.b_relationship as b_relationship1," +
					"i2.name as name2," +
					"i2.gender as gender2,to_char(i2.birthday,'yyyymmdd') as BIRTH2,i2.idtype as idtype2,i2.id as id2,i2.address as address2," +
					"i2.zipcode as zipcode2,i2.tel as tel2,i2.mobile as mobile2,i2.email as email2 " +
					"from workorder2 w left join tabcinsurance t1 on w.workorder_guid=t1.relation_id left join staff s on s.staff_id=w.createdby " +
					"left join staffrolegroup sr on s.staff_id=sr.staff_id left join rolegroup r on r.rolegroup_id=sr.rolegroup_id " +
					"left join policy p1 on p1.pol_guid=t1.pol_package left join staff s1 on s1.staff_id=t1.QA_staff " +
					"left join (select cust_guid,relation_id,name,gender,birthday,idtype,upper(id) id,address,zipcode,tel,mobile,email,jobcode," +
					"b_relationship from insurance_cust where cust_type=1) i1 on i1.relation_id=t1.relation_id left join " +
					"(select cust_guid,relation_id,name,gender,birthday,idtype,upper(id) id,address,zipcode,tel,mobile,email," +
					"jobcode,b_relationship from insurance_cust where cust_type=2) i2 on i2.relation_id=t1.relation_id " +
					"where  t1.relation_id='"+realtionID+"'";
			log.debug("sql1:"+sql1);
			List list1=ISPayServlet.ebean.chaxun_sql(sql1,dataSource1);
			if(list1!=null&&list1.size()>0){
				Map map1=(Map)list1.get(0);
				APPL_NO_QA=Util.getString(map1.get("APPL_NO_QA"));
				DIST="<DIST><SEAT_DEPT>"+Util.getString(map1.get("dept_code"))+"</SEAT_DEPT>" +
						"<SEAT_CODE>"+Util.getString(map1.get("loginname1"))+"</SEAT_CODE>" +
						"<BATCH_NO>"+Util.getString(map1.get("CUSTLISTNAME"))+"</BATCH_NO><INSU>1</INSU></DIST>";
				log.debug("DIST:"+DIST);
				BUSI_pre="<TRSDATE>"+Util.getString(map1.get("TRSDATE"))+"</TRSDATE><TRANS>"+Util.getString(map1.get("CNTR_PRESS_NO"))+"</TRANS><CATE>2</CATE><SUBJECT>1</SUBJECT>";
				log.debug("BUSI_pre:"+BUSI_pre);
				MAIN="<MAIN><APPNO>"+Util.getString(map1.get("APPL_NO_QA"))+"</APPNO>" +
						"<APPDATE>"+Util.getString(map1.get("APPDATE"))+"</APPDATE>" +
						"<ORGAN>"+Util.getString(map1.get("third_company_organ"))+"</ORGAN>" +
						"<BLUE_CODE>"+Util.getString(map1.get("pol_code"))+"</BLUE_CODE>" +
						"<BALE_NO>"+Util.getString(map1.get("simple_id"))+"</BALE_NO>" +
						"<PAY_WAY>"+Util.getString(map1.get("ERNST_MONEYIN_TYPE"))+"</PAY_WAY>" +
						"<PAYBANK>"+Util.getString(map1.get("BANK_CODE"))+"</PAYBANK>" +
						"<PAYACC>"+Util.getString(map1.get("BANKACC_NO"))+"</PAYACC>" +
						"<ACCTYPE>"+Util.getString(map1.get("BANKACC_TYPE"))+"</ACCTYPE>" +
						"<PAY_T>"+Util.getString(map1.get("MONEYIN_TYPE"))+"</PAY_T>" +
						"<PARTNER_CARDNO></PARTNER_CARDNO>" +
						"<DELIVER>"+Util.getString(map1.get("trans_way"))+"</DELIVER>" +
						"<DELIVER_DATE>"+Util.getString(map1.get("DELIVER_DATE"))+"</DELIVER_DATE>" +
						"<DELIVER_MEMO>"+Util.getString(map1.get("trans_address"))+"</DELIVER_MEMO>" +
						"<DELIVER></DELIVER>" +
						"<SPEC></SPEC><PRINTED>0</PRINTED><FAMILY_TYPE>0</FAMILY_TYPE><FAMILY_APP_ID></FAMILY_APP_ID>" +
						"<INSPECT_EMP>"+Util.getString(map1.get("loginname"))+"</INSPECT_EMP>" +
						"<INSPECT_TIME>"+Util.getString(map1.get("INSPECT_TIME"))+"</INSPECT_TIME>" +
						"<INITIAL_PREMIUM>"+Util.getString(map1.get("INITIAL_PREMIUM"))+"</INITIAL_PREMIUM>" +
						"<MON_NUM_PERIOD>"+Util.getString(map1.get("mon_num_period"))+"</MON_NUM_PERIOD>" +
						"<AUTH_NO></AUTH_NO><AUTH_DATE></AUTH_DATE><KIDS_DEATH_AMOUNT></KIDS_DEATH_AMOUNT>" +
						"<DELIVER_ADDR>"+Util.getString(map1.get("trans_address"))+"</DELIVER_ADDR>" +
						"<ACCOUNT_OWNER>"+Util.getString(map1.get("bank_owner"))+"</ACCOUNT_OWNER>" +
						"<PAID_STATUS>"+Util.getString(map1.get("ivr_paid_status"))+"</PAID_STATUS>" +
						"<PAID_DATE>"+Util.getString(map1.get("ivr_paid_date"))+"</PAID_DATE>" +
						"<BANK_CODE>"+Util.getString(map1.get("ivr_bank_code"))+"</BANK_CODE>" +
						"<ORDER_NO>"+Util.getString(map1.get("ivr_order_no"))+"</ORDER_NO>" +
						"<TRANSFER>"+Util.getString(map1.get("ps_trans_way"))+"</TRANSFER>" +
						"<TRANSFER_DATE>"+Util.getString(map1.get("TRANSFER_DATE123"))+"</TRANSFER_DATE>" +
						"<TRANSFER_MEMO>"+Util.getString(map1.get("trans_comment"))+"</TRANSFER_MEMO>" +
						"<ISSUE_MODE>"+Util.getString(map1.get("ps_issue_mode"))+"</ISSUE_MODE>" +
						"<TRANSFER_ADDR>"+Util.getString(map1.get("trans_address"))+"</TRANSFER_ADDR>" + 
						"</MAIN>";
				log.debug("MAIN:"+MAIN);
				TBR="<TBR><NAME>"+Util.getString(map1.get("name1"))+"</NAME>" +
						"<SEX>"+Util.getString(map1.get("gender1"))+"</SEX>" +
						"<BIRTH>"+Util.getString(map1.get("BIRTH1"))+"</BIRTH>" +
						"<IDTYPE>"+Util.getString(map1.get("idtype1"))+"</IDTYPE>" +
						"<IDNO>"+Util.getString(map1.get("id1"))+"</IDNO>" +
						"<ADDR>"+Util.getString(map1.get("address1"))+"</ADDR>" +
						"<ZIP>"+Util.getString(map1.get("zipcode1"))+"</ZIP>" +
						"<TEL>"+Util.getString(map1.get("tel1"))+"</TEL>" +
						"<TEL_OFFICE></TEL_OFFICE>" +
						"<MP>"+Util.getString(map1.get("mobile1"))+"</MP>" +
						"<EMAIL>"+Util.getString(map1.get("email1"))+"</EMAIL>" +
						"<OCCUP></OCCUP><BBR_RELA>"+Util.getString(map1.get("b_relationship1"))+"</BBR_RELA></TBR>";
				log.debug("TBR:"+TBR);
				BBR_pre="<NAME>"+Util.getString(map1.get("name2"))+"</NAME>" +
				        "<SEX>"+Util.getString(map1.get("gender2"))+"</SEX>" +
				        "<BIRTH>"+Util.getString(map1.get("BIRTH2"))+"</BIRTH>" +
				        "<IDTYPE>"+Util.getString(map1.get("idtype2"))+"</IDTYPE>" +
				        "<IDNO>"+Util.getString(map1.get("id2"))+"</IDNO>" +
				        "<ADDR>"+Util.getString(map1.get("address2"))+"</ADDR>" +
				        "<ZIP>"+Util.getString(map1.get("zipcode2"))+"</ZIP>" +
				        "<TEL>"+Util.getString(map1.get("tel2"))+"</TEL>" +
				        "<TEL_OFFICE></TEL_OFFICE>" +
				        "<MP>"+Util.getString(map1.get("mobile2"))+"</MP>" +
				        "<EMAIL>"+Util.getString(map1.get("email2"))+"</EMAIL>" +
						"<OCCUP></OCCUP>";
				log.debug("BBR_pre:"+BBR_pre);
			}
			String sql2="select name,gender,to_char(birthday,'yyyymmdd') as BIRTH,idtype,upper(id) as IDNO," +
					"b_index,INTERESTPERCENT,b_relationship from INSURANCE_cust where RELATION_ID='"+realtionID+"' and cust_type=3";
			log.debug("sql2:"+sql2);
			List list2=ISPayServlet.ebean.chaxun_sql(sql2,dataSource1);
			if(list2!=null&&list2.size()>0){
				for(int i=0;i<list2.size();i++){
					Map map2=(Map)list2.get(i);
					SYR=SYR+"<SYR><NAME>"+Util.getString(map2.get("name"))+"</NAME>" +
							"<SEX>"+Util.getString(map2.get("gender"))+"</SEX>" +
							"<BIRTH>"+Util.getString(map2.get("BIRTH"))+"</BIRTH>" +
							"<IDTYPE>"+Util.getString(map2.get("idtype"))+"</IDTYPE>" +
							"<IDNO>"+Util.getString(map2.get("IDNO"))+"</IDNO>" +
							"<ORDER>"+Util.getString(map2.get("b_index"))+"</ORDER>" +
							"<RATIO>"+Util.getString(map2.get("INTERESTPERCENT"))+"</RATIO>" +
							"<BBR_RELA>"+Util.getString(map2.get("b_relationship"))+"</BBR_RELA></SYR>";
				}
			}
			log.debug("SYR:"+SYR);
			String sql3="select i.pol_code,i.face_amnt,i.chargeperiod,i.MONEYIN_DUR,i.coverageperiod," +
					"i.INSUR_DUR,'','','','',i.premium*100 as PREMIUM,i.premium*t.mon_num_period*100 as INITIAL_PREMIUMOFPT," +
					"'','','',1.00 from insurance i left join tabcinsurance t on t.relation_id=i.relation_id " +
					"left join policy_package p on p.pol_guid=t.pol_package and p.simple_id=to_char(t.simple_id) " +
					"and p.item_guid=i.pol_guid where i.relation_id='"+realtionID+"' order by p.plan_seq";
			log.debug("sql3:"+sql3);
			List list3=ISPayServlet.ebean.chaxun_sql(sql3,dataSource1);
			if(list3!=null&&list3.size()>0){
				for(int i=0;i<list3.size();i++){
					Map map3=(Map)list3.get(i);
					PT=PT+"<PT><ID>"+Util.getString(map3.get("pol_code"))+"</ID>" +
							"<UNIT>"+Util.getString(map3.get("face_amnt"))+"</UNIT>" +
							"<CRG_T>"+Util.getString(map3.get("chargeperiod"))+"</CRG_T>" +
							"<CRG_Y>"+Util.getString(map3.get("MONEYIN_DUR"))+"</CRG_Y>" +
							"<COVER_T>"+Util.getString(map3.get("coverageperiod"))+"</COVER_T>" +
							"<COVER_Y>"+Util.getString(map3.get("INSUR_DUR"))+"</COVER_Y>" +
							"<DRAW_T></DRAW_T><DRAW_FST></DRAW_FST><DRAW_LST></DRAW_LST><DRAW_ENSURE></DRAW_ENSURE>" +
							"<PREMIUM>"+Util.getString(map3.get("PREMIUM"))+"</PREMIUM>" +
							"<INITIAL_PREMIUMOFPT>"+Util.getString(map3.get("INITIAL_PREMIUMOFPT"))+"</INITIAL_PREMIUMOFPT>" +
							"<PR_TYPE></PR_TYPE><FREE_TYPE></FREE_TYPE><FREE_MONTH></FREE_MONTH><DISCOUNT_RATE>1.00</DISCOUNT_RATE></PT>";
				}
			}
			log.debug("PT:"+PT);
			TxXml="<TX><REQUEST>"+DIST+"<BUSI>"+BUSI_pre+"<CONTENT>"+MAIN+TBR+"<BBR>"+BBR_pre+SYR+"</BBR><PTS>"+PT+"</PTS></CONTENT></BUSI></REQUEST></TX>";
		}catch(Exception e){
			log.error("getTxXml(String realtionID):"+Util.getERRO(e));
		}
		String param=TxXml;
		if(param.length()>1000){
			param=param.substring(0,1000);
		}
		try{
			if(type.equals("01")){
				ISPayServlet.ebean.ISIvrPay_log(APPL_NO_QA,"调用同步接口前",param,"01tongbu_01",100,realtionID,dataSource1);
			}else if(type.equals("02")){
				ISPayServlet.ebean.ISIvrPay_log(APPL_NO_QA,"调用同步接口前",param,"02tongbu_01",100,"",dataSource1);
			}
		}catch(Exception e){
			try{
				if(type.equals("01")){
					ISPayServlet.ebean.ISIvrPay_log(APPL_NO_QA,"调用同步接口前","返回乱码，具体查阅日志","01tongbu_01",100,realtionID,dataSource1);
				}else if(type.equals("02")){
					ISPayServlet.ebean.ISIvrPay_log(APPL_NO_QA,"调用同步接口前","返回乱码，具体查阅日志","02tongbu_01",100,"",dataSource1);
				}
			}catch(Exception e1){
				log.error(Util.getERRO(e1));
			}
			log.error(Util.getERRO(e));
		}
		return TxXml;
	}
	private void dorun1(DataSource dataSource1) throws DocumentException{
		String xml="";
		String sql="select t.relation_id as workorder_guid from workorder2 w left join tabcinsurance t on w.workorder_guid=t.relation_id inner join staff s on s.staff_id=w.createdby where w.workorderstatus='OPEN' and curstep_id in ('N00022','N00025','N00030') and (t.ivr_tb_flag=0 or t.ivr_tb_flag is null) and ivr_flag=1";
	    List list=ISPayServlet.ebean.chaxun_sql(sql, dataSource1);
	    if(list!=null&&list.size()>0){
	    	for(int i=0;i<list.size();i++){
	    		Map map=(Map)list.get(i);
				String workorder_guid=(String)map.get("workorder_guid");
				xml=getTongBuXML(workorder_guid,dataSource1); 
			    xml="<?xml version='1.0' encoding='GBK'?><TXS>"+xml+"</TXS>";
			    String returnxml=ISPayThread.getReturnXml(xml,"02");
			    if(returnxml==null||returnxml.equals("")||returnxml.length()==0){
			    	ISPayServlet.ebean.ISIvrPay_log("","调用同步接口后",returnxml,"02tongbu_02",3,workorder_guid,dataSource1);
			    }
				parserXml(returnxml,dataSource1,"02","");
	    	}
	    }
	}
	private void dorun(){
		String sql="select mproject_id from multiproject where mproject_id!='gzl111' ";
		log.debug("sql:"+sql);
		List list=ISPayServlet.ebean.chaxun_sql1(sql);
		if(list!=null&&list.size()>0){
			for(int i=0;i<list.size();i++){
				Map map=(Map)list.get(i);
				String mproject_id=(String)map.get("mproject_id");
				DataSource dataSource1=(DataSource)ISPayServlet.wac.getBean(mproject_id);
				try {
					dorun1(dataSource1);
				} catch (DocumentException e) {
					log.error("dorun():"+Util.getERRO(e));
				}
			}
		} 
	}
	public static String getReturnXml(String xml,String protocol_value){
		String returnxml="";
		String response=""; 
		try{
			log.debug("ISPayServlet.AcceptProposalApp_url:"+ISPayServlet.AcceptProposalApp_url);
		    returnxml=ISPayServlet.ISPayConnection(ISPayServlet.AcceptProposalApp_url,"","",xml,"protocol",protocol_value,"packet");
//		    returnxml=ISPayServlet.ISPayConnection("http://10.1.17.115/life/servlet/com.tpdm.onlinepayment.AcceptProposalAppServlet","","",xml,"protocol","01","packet");
	        log.info("returnxml:"+returnxml);
		}catch(Exception e){
			log.error("getReturnXml:"+Util.getERRO(e));
		}
		return returnxml;
	}
	public static String getTongBuXML(String realtionID,DataSource dataSource1){
		String TxXml=ISPayThread.getTxXml(realtionID,dataSource1,"02");
		return TxXml;
	}
	public static void main(String[] args){
		String xml="<?xml version='1.0' encoding='UTF-8' ?><response><import_apps><app><SEQ>1</SEQ><APPNO>000367546626309</APPNO><PROC_STS>已处理</PROC_STS><ERR_CODE>0</ERR_CODE><ERR_DESC><![CDATA[]]></ERR_DESC></app><app><SEQ>2</SEQ><APPNO>000367597607309</APPNO><PROC_STS>已处理</PROC_STS><ERR_CODE>0</ERR_CODE><ERR_DESC><![CDATA[]]></ERR_DESC></app></import_apps></response>";
		Document doc=null;
		try {
			doc = DocumentHelper.parseText(xml);
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		Element root=doc.getRootElement(); 
//		Element response=root.element("response");
		Element import_apps=root.element("import_apps");
		Iterator iters=import_apps.elementIterator();
		while(iters.hasNext()){
			Element app=(Element)iters.next();
			Element ERR_CODE_Element=app.element("ERR_CODE");
			String ERR_CODE=ERR_CODE_Element.getText();
			System.out.println("ERR_CODE:"+ERR_CODE);
		}
		
	}
	public static void parserXml(String xml,DataSource dataSource1,String protocol,String realtionID) throws DocumentException{
		Document doc=DocumentHelper.parseText(xml); 
		log.info("xml:"+xml);
		String param=xml;
		if(param.length()>1000){
			param=param.substring(0,1000);
		}
		Element root=doc.getRootElement(); 
		Element import_apps=root.element("import_apps");
		Iterator iters=import_apps.elementIterator();
		while(iters.hasNext()){
			try{
				int flag=0;
				String ERR_CODE="";
				String ERR_DESC="";
				Element app=(Element)iters.next();
				Element ERR_CODE_Element=app.element("ERR_CODE");
				ERR_CODE=ERR_CODE_Element.getText();
				Element ERR_DESC_Element=app.element("ERR_DESC");
				ERR_DESC=ERR_DESC_Element.getText();
				Element APPNO_Element=app.element("APPNO");
				String APPNO_CODE=APPNO_Element.getText();
				if(ERR_CODE.equals("0")||ERR_CODE.equals("")){
					flag=1;
					try{
						if(protocol.equals("02")){
							ISPayServlet.ebean.ISIvrPay_log(APPNO_CODE,"调用同步接口后",param,"02tongbu_02",1,"",dataSource1);
						}else if(protocol.equals("01")){
							ISPayServlet.ebean.ISIvrPay_log(APPNO_CODE,"调用同步接口后",param,"01tongbu_02",1,realtionID,dataSource1);
						}
					}catch(Exception e){
						try{
							if(protocol.equals("02")){
								ISPayServlet.ebean.ISIvrPay_log(APPNO_CODE,"调用同步接口后","返回乱码，具体查阅日志","02tongbu_02",1,"",dataSource1);
							}else if(protocol.equals("01")){
								ISPayServlet.ebean.ISIvrPay_log(APPNO_CODE,"调用同步接口后","返回乱码，具体查阅日志","01tongbu_02",1,realtionID,dataSource1);
							}
						}catch(Exception e1){
							log.error(Util.getERRO(e1));
						}

						log.error(Util.getERRO(e));
					}
				}else{
					try{
						if(protocol.equals("02")){
							ISPayServlet.ebean.ISIvrPay_log(APPNO_CODE,"调用同步接口后",param,"02tongbu_02",0,"",dataSource1);
						}else if(protocol.equals("01")){
							ISPayServlet.ebean.ISIvrPay_log(APPNO_CODE,"调用同步接口后",param,"01tongbu_02",0,realtionID,dataSource1);
						}
					}catch(Exception e){
						try{
							if(protocol.equals("02")){
								ISPayServlet.ebean.ISIvrPay_log(APPNO_CODE,"调用同步接口后","返回乱码，具体查阅日志","02tongbu_02",0,"",dataSource1);
							}else if(protocol.equals("01")){
								ISPayServlet.ebean.ISIvrPay_log(APPNO_CODE,"调用同步接口后","返回乱码，具体查阅日志","01tongbu_02",0,realtionID,dataSource1);
							}
						}catch(Exception e1){
							log.error(Util.getERRO(e1));
						}
						log.error(Util.getERRO(e));
					}
				}
				if(protocol.equals("02")){
					String sql="update tabcinsurance set ivr_tb_flag="+flag+",ivr_err_desc='"+ERR_DESC+"',ivr_err_code='"+ERR_CODE+"' where appl_no_qa='"+APPNO_CODE+"' and appl_no_qa is not null";	
					log.debug("sql:"+sql);
					int result=ISPayServlet.ebean.update_sql(sql,dataSource1);
					log.debug("result:"+result);
				}else if(protocol.equals("01")){
					String ISIvrPay_result=ISPayServlet.ebean.ISIvrPay_Tongbu(APPNO_CODE,flag,dataSource1,ERR_CODE,ERR_DESC);
					log.debug("ISIvrPay_result:"+ISIvrPay_result);
				}else{
					log.error("protocol:"+protocol);
				}
			}catch(Exception e){
				log.error("parserXml(String xml,DataSource dataSource1):"+Util.getERRO(e));
			}
		}
	}
	public void run(){
		log.info("－－－－－－－－－－－－－－－－－－－ISPayThread（372）－－－－－－－－－－－－－－－－－－");
		while(flag){
			try{
				Date date=new Date();
				String nowtime=String.format("%tR",date); //获取现在几点
				String daytime=String.format("%tF",date);
				log.debug("nowtime:"+nowtime);
				nowtime=nowtime.substring(0,2);
				log.debug("nowtime_pro:"+nowtime);
				log.debug("judge_daytime:"+judge_daytime);
				log.debug("daytime:"+daytime);
				String dotime1=ISPayServlet.ebean.chaxunString();
				log.debug("dotime1:"+dotime1);
//				if((nowtime.equals(dotime1))&&(!judge_daytime.equals(daytime)))
				if(nowtime.equals(dotime1)){
//					coreSyncService.syncCore(); 
					dorun();
					judge_daytime=daytime;
				}
			}catch(Exception e){
				log.error("run():"+Util.getERRO(e));
			}        
			try{
				log.debug("时间未到，休眠59分");
            	Thread.sleep(59*60*1000);
            }catch(Exception e){
            	log.error("定时错误:"+Util.getERRO(e)); 
            }
		}
	}

}
